package com.example.baguwen.controller;

import com.example.baguwen.common.Result;
import com.example.baguwen.repository.BaguwenRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/baguwen/types")
public class BaguwenTypeController {
    
    @Autowired
    private JdbcTemplate jdbcTemplate;
    
    @GetMapping
    public Result<List<Map<String, Object>>> getAllTypes() {
        // 查询所有不同的类型及其对应的八股文数量
        String sql = "SELECT type, COUNT(id) as count FROM baguwen WHERE is_deleted = false GROUP BY type ORDER BY count DESC";
        List<Map<String, Object>> types = jdbcTemplate.queryForList(sql);
        
        return Result.success(types);
    }
} 